package mo.tags.greedy;

import java.util.Arrays;
import java.util.Comparator;

public class L452 {

    public int findMinArrowShots(int[][] points) {
        int n = points.length;
        if (n == 0) {
            return 0;
        }
        //[[3,9],[7,12],[3,8],[6,8],[9,10],[2,9],[0,9],[3,9],[0,6],[2,8]]
        Arrays.sort(points, Comparator.comparingInt(p -> p[1]));
        int res = 1;
        int right = points[0][1];
        for (int i = 1; i < n; i++) {
            if (right < points[i][0]) {
                res++;
                right = points[i][1];
            }
        }
        return res;
    }

    public static void main(String[] args) {
        L452 test = new L452();
        System.out.println(test.findMinArrowShots(new int[][]{{3,9},{7,12},{3,8},{6,8},{9,10},{2,9},{0,9},{3,9},{0,6},{2,8}}));
    }

}
